package com.fs.controller;

import com.fs.entity.Attractions;
import com.fs.entity.User;
import com.fs.service.UserService;
import com.fs.util.ResponseData;
import com.fs.util.ResponseDataUtil;
import com.fs.util.ResultEnums;
import com.fs.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hua
 * @version 1.0
 * @title UserController
 * @description
 * @create 2024/4/19 9:59
 */
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    public ResponseData list(UserVo userVo, int pageNum, int pageSize)
    {
        List<User> users = userService.selectPageByUserVo(userVo, pageNum, pageSize);
        return ResponseDataUtil.buildOk(users);
    }

    @PostMapping("/add")
    public ResponseData add(@RequestBody User user)
    {
        userService.insert(user);
        return ResponseDataUtil.buildOk(ResultEnums.CREATED);
    }

    @PostMapping("/update")
    public ResponseData update(@RequestBody User user)
    {
        userService.update(user);
        return ResponseDataUtil.buildOk(ResultEnums.UPDATED);
    }

    @RequestMapping("/delete")
    public ResponseData delete(int id)
    {
        userService.delete(id);
        return ResponseDataUtil.buildOk(ResultEnums.DELETED);
    }

    @RequestMapping("/login")
    public ResponseData login(String username,String password)
    {
        return userService.Login(username,password);
    }
}
